from typing import Optional, List
from pydantic import BaseModel, Field


class Token(BaseModel):
    """JWT Token Schema"""
    access_token: str
    token_type: str = "bearer"
    expires_in: int = 3600  # 1小时
    refresh_token: Optional[str] = None
    scope: Optional[str] = None


class TokenData(BaseModel):
    """Token数据Schema"""
    user_id: Optional[int] = None
    username: Optional[str] = None
    email: Optional[str] = None
    roles: List[str] = []
    permissions: List[str] = []
    is_superuser: bool = False


class LoginRequest(BaseModel):
    """登录请求Schema"""
    email: str = Field(..., min_length=1, max_length=100)
    password: str = Field(..., min_length=6, max_length=128)


class RefreshTokenRequest(BaseModel):
    """刷新Token请求Schema"""
    refresh_token: str = Field(..., min_length=10)


class ChangePasswordRequest(BaseModel):
    """修改密码请求Schema"""
    current_password: str = Field(..., min_length=6, max_length=128)
    new_password: str = Field(..., min_length=6, max_length=128)


class ResetPasswordRequest(BaseModel):
    """重置密码请求Schema"""
    email: str = Field(..., min_length=1, max_length=100)


class UserAuthInfo(BaseModel):
    """用户认证信息"""
    user_id: int
    username: str
    email: str
    roles: List[str]
    permissions: List[str]
    is_superuser: bool
    is_active: bool
    last_login_at: Optional[str] = None